/**
 * 
 */
package com.EstateManager.Dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.EstateManager.Entity.Estatebasicinfo;
import com.EstateManager.Entity.Estateinfofile;

/**
 * 创建时间 : 上午8:48:26
 * @author Yonggang Liu
 *
 * EstateInfoFileDao.java
 */
@Repository("estateInfoFileDao")
public class EstateInfoFileDao implements IModelBasicOperate<Estateinfofile, Integer> {
    
	public final static String FILE_CHECK = "验证文件";
	
	public final static String FILE_DESCRIB = "描述文件";
	
	@Autowired
	private SessionFactory sessionFactory;
	
    private Session getCurrentSession(){
    	return sessionFactory.getCurrentSession();
    }
	
    
    
    
	@Override
	public Estateinfofile load(Integer id) throws HibernateException {
		
		return (Estateinfofile)this.getCurrentSession().load(Estateinfofile.class, id);
	}

	@Override
	public Estateinfofile get(Integer id) throws HibernateException {
		return (Estateinfofile)this.getCurrentSession().get(Estateinfofile.class, id);
	}

	
	@Override
	public void persist(Estateinfofile entity) throws HibernateException {
		this.getCurrentSession().persist(entity);
		
	}

	
	@Override
	public Integer save(Estateinfofile entity) throws HibernateException {
		return (Integer)this.getCurrentSession().save(entity);
	}

	
	@Override
	public void saveOrUpdate(Estateinfofile entity) throws HibernateException {
		this.getCurrentSession().saveOrUpdate(entity);
	}

	

	
	@Override
	public void flush() throws HibernateException {
		this.getCurrentSession().flush();
		
	}

	@Override
	public void update(Estateinfofile entity) throws HibernateException {
		this.getCurrentSession().update(entity);
	}

	@Override
	public void merge(Estateinfofile entity) throws HibernateException {
		this.getCurrentSession().merge(entity);
	}
	
	/**
	 * 根据文件类型查询文件信息列表
	 * @param type 文件类型
	 * @param estateInfoId
	 * */
	public List<Estateinfofile> getListByType(String type, int estateInfoId) throws HibernateException {
		Estatebasicinfo estatebasicinfo = new Estatebasicinfo();
		estatebasicinfo.setId(estateInfoId);
		Query query = this.getCurrentSession().createQuery("select estateinfofile "
												+ "from Estateinfofile estateinfofile "
												+ "where estateinfofile.fileType = :fileType and estateinfofile.estatebasicinfo = :estatebasicinfo");
		query.setParameter("fileType", type);
		query.setParameter("estatebasicinfo", estatebasicinfo);
		return (List<Estateinfofile>)query.list();
	}




	/* (non-Javadoc)
	 * @see com.EstateManager.Dao.IModelBasicOperate#detete(java.lang.Object)
	 */
	@Override
	public void detete(Estateinfofile entity) throws HibernateException {
		this.getCurrentSession().delete(entity);
	}

}
